<?php
define ('IN_P_ENIGMA', FALSE);

include_once ('config.php');

include_once ($config['inc_dir'] . 'db.php');
$db = new db($config['dbhost'], $config['dbuser'], $config['dbpass'], $config['dbname']);

include_once ($config['inc_dir'] . 'constant.php');

include_once ($config['inc_dir'] . 'work.php');
$work = new work();

include_once ($config['inc_dir'] . 'user.php');
$user = new user();

include_once ($config['inc_dir'] . 'template.php');
$template = new template($work->config['site_url'], $work->config['site_dir'], $user->data['theme'], $user->data['faction']);
$title = $work->config['title'];
$header_footer = true;
$template_output = true;

if (!isset($_GET['action']) || empty($_GET['action']) || $_GET['action'] == 'index' || $work->url_check())
{
	$action = 'main';
}
else if (!SERVER_NO && !in_array($_GET['action'], $all_aviable))
{
	$action = 'main';
}
else
{
	$action = $_GET['action'];
	if (!file_exists($work->config['site_dir'] . 'action/' . $action . '.php')) $action = 'main';
}

include_once ($config['inc_dir'] . 'language.php');
$language = new language($work->config['site_dir'], $user->data['language'], $action);
$local_menu = $language->local_menu();
$user->check_allow_login();

include_once($work->config['site_dir'] . 'action/' . $action . '.php');
$user->last_active();
$template->create_template();
$debug = false;

if ($work->config['debug'])
{
	$debug = htmlspecialchars(var_export($db, true)) . '<br />';
	$debug .= htmlspecialchars(var_export($work, true)) . '<br />';
	$debug .= htmlspecialchars(var_export($user, true)) . '<br />';
	$debug .= htmlspecialchars(var_export($language, true)) . '<br />';
	$debug .= htmlspecialchars(var_export($template, true)) . '<br />';
	$debug .= htmlspecialchars(var_export($_SESSION, true)) . '<br />';
	$debug = '<pre>' . $debug . '</pre>';
}

if ($header_footer)
{
	$template->page_header($title, $local_menu);
	$template->page_footer($debug);
}
if ($template_output) echo $template->content;
?>
